package com.boco.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.dao.GetEMR_CYXJXData;
import com.boco.dao.SentData;
import com.boco.entity.EMR_CYXJX;

public class InsertEMR_CYXJXDataAction {
	private static final Log log = LogFactory.getLog(InsertEMR_CYXJXDataAction.class);
	public  String insertData(){
		String url = "http://fasong.cdxp.csb/json/dzbl4";
		String resule = null;
		List<EMR_CYXJX> list = new ArrayList<EMR_CYXJX>();
		list = GetEMR_CYXJXData.getData();
		
	    log.info("########################################");
	    log.info("数据总条数："+list.size());
	    log.info("########################################");
		String userName = "dzbl4";
		String password = "322dfbf9048445cabb06cbf24e64cdcf";
		EMR_CYXJX temp = null;
		
		for(int i=0;i<list.size();i++){
			String param = null;
			temp = list.get(i);
			//log.info(temp.getXM());
			//按照身份证删除已经存在的值。
			param = "{\"SQL\":\"delete  EMR_CYXJX where ZYH='"+
					temp.getZYH()
					+"'"
					+" and YLJGZZJGDM='"+temp.getYLJGZZJGDM() +"'"
					+ "\", \"ANNOTION\":\"cdxplogs\"}";
			resule = SentData.sendPost(url, param, userName, password);
			log.info("删除结果："+resule);
			param = "{\"SQL\":\"INSERT INTO EMR_CYXJX ("
					+ "HZZSYH,"
					+ "YLJGZZJGDM,"
					+ "YLJGMC,"
					+ "ZYH,"
					+ "XM,"
					+ "XB,"
					+ "NL,"
					+ "CSRQ,"
					+ "XXXDZ,"
					+ "GZDW,"
					+ "CSD,"
					+ "MZDM,"
					+ "HYZKDM,"
					+ "ZYLBDM,"
					+ "ZYYSGH,"
					+ "ZYYSMC,"
					+ "ZYYSQMSJ,"
					+ "ZZYSGH,"
					+ "ZZYSQM,"
					+ "ZZYSQMSJ,"
					+ "CYXJLX,"
					+ "RYRQSJ,"
					+ "CYRQSJ,"
					+ "RYKSDM,"
					+ "RYKSMC,"
					+ "BCH,"
					+ "SJZYTS,"
					+ "RYZDDM,"
					+ "RYZD,"
					+ "RYQK,"
					+ "ZLGCMS,"
					+ "CYQK,"
					+ "CYZDDM,"
					+ "CYZD,"
					+ "CYYZ,"
					+ "ZLJGDM,"
					+ "YXFZJCJG,"
					+ "ZYSZGCJGMS,"
					+ "SSGCMS,"
					+ "ZZZF,"
					+ "ZYJZFF,"
					+ "ZYYYFF,"
					+ "CYSZZYTZ,"

					+ "BCRQ,"
					+ "ZRLSH,"
					+ "ORGCODE,"
					+ "AREACODE,"
					+ "UPLOADTIME,"
					+ "SOURCEID"
					+ ") VALUES("
					+ "'" + checkStr(temp.getHZZSYH()) + "'," 
					+ "'" + checkStr(temp.getYLJGZZJGDM()) + "'," 
					+ "'" + checkStr(temp.getYLJGMC()) + "'," 
					+ "'" + checkStr(temp.getZYH()) + "'," 
					+ "'" + checkStr(temp.getXM()) + "'," 
					+ "'" + checkStr(temp.getXB()) + "'," 
					+ "'" + checkStr(temp.getNL()) + "'," 
					+ "to_date('" + checkStr(temp.getCSRQ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getXXXDZ()) + "'," 
					
					+ "'" + checkStr(temp.getGZDW()) + "'," 
					+ "'" + checkStr(temp.getCSD()) + "',"
					+ "'" + checkStr(temp.getMZDM()) + "',"
					+ "'" + checkStr(temp.getHYZKDM()) + "'," 
					+ "'" + checkStr(temp.getZYLBDM()) + "'," 
					+ "'" + checkStr(temp.getZYYSGH()) + "'," 
					+ "'" + checkStr(temp.getZYYSMC()) + "'," 
					+ "to_date('" + checkStr(temp.getZYYSQMSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					
					+ "'" + checkStr(temp.getZZYSGH()) + "'," 
					+ "'" + checkStr(temp.getZZYSQM()) + "',"
					+ "to_date('" + checkStr(temp.getZZYSQMSJ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getCYXJLX()) + "'," 
					+ "to_date('" + checkStr(temp.getRYRQSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "to_date('" + checkStr(temp.getCYRQSJ()) + "','yyyy-MM-dd HH24:mi:ss')," 
					+ "'" + checkStr(temp.getRYKSDM()) + "'," 
					+ "'" + checkStr(temp.getRYKSMC()) + "'," 
					+ "'" + checkStr(temp.getBCH()) + "'," 
					+ "'" + checkStr(temp.getSJZYTS()) + "'," 
					+ "'" + checkStr(temp.getRYZDDM()) + "'," 
					+ "'" + checkStr(temp.getRYZD()) + "'," 
					+ "'" + checkStr(temp.getRYQK()) + "'," 
					
					+ "'" + checkStr(temp.getZLGCMS()) + "',"
					+ "'" + checkStr(temp.getCYQK()) + "',"
					+ "'" + checkStr(temp.getCYZDDM()) + "'," 
					+ "'" + checkStr(temp.getCYZD()) + "'," 
					+ "'" + checkStr(temp.getCYYZ()) + "'," 
					+ "'" + checkStr(temp.getZLJGDM()) + "'," 
					+ "'" + checkStr(temp.getYXFZJCJG()) + "'," 
					
					+ "'" + checkStr(temp.getZYSZGCJGMS()) + "',"
					+ "'" + checkStr(temp.getSSGCMS()) + "',"
					+ "'" + checkStr(temp.getZZZF()) + "'," 
					+ "'" + checkStr(temp.getZYJZFF()) + "'," 
					+ "'" + checkStr(temp.getZYYYFF()) + "'," 
					+ "'" + checkStr(temp.getCYSZZYTZ()) + "'," 
				
					
					
					+ "to_date('" + checkStr(temp.getBCRQ()) + "','yyyy-MM-dd HH24:mi:ss'),"
					+ "'" + checkStr(temp.getZRLSH()) + "'," 
					+ "'" + checkStr(temp.getORGCODE()) + "'," 
					+ "'" + checkStr(temp.getAREACODE()) + "'," 
					+ "sysdate," 
					+ "'dzbl4'" 
					+ ")\", \"ANNOTION\":\"cdxplogs\"}";
					resule = SentData.sendPost(url, param, userName, password);
					log.info(resule);
					
		}
		log.info("上传完成！");
		return resule;
		
	
		
	}
	
	public static String checkStr(Object obj){
		if (obj== null){
			obj = "";
		}
		return (String) obj;
	}
	
	
}
